function [OUT_Bits_Decoded DemodDescrambled_Data N_Blocks] = HF_RECEIVER(RX_Input_Frames,N_Frames,Rate,Interleaver_L,Sigma,fadingSymbols,alpha,MSE_Real, MSE)

global trellis_t
%*--------------------------------------- FRAME PROCESSING --------------------------------------%

for frame_index = 1:N_Frames

    %SOFT VALUE Demodulation
    %------------------------
    if (Rate == 3200 || Rate == 4800)            %Q&8PSK
        % Descrampling for PSK path
        %--------------------------
        Descrambled_Data(frame_index,:)           = HF_Descrambling_PSK(RX_Input_Frames(frame_index,:),Rate);
        % Soft Demodulation for PSK path
        %-------------------------------
        Demodulated_Data(frame_index,:)           = HF_DemodSoft_PSK(Descrambled_Data(frame_index,:),Rate,Sigma,fadingSymbols(frame_index,:),MSE_Real(frame_index,:), MSE(frame_index,:));
        DemodDescrambled_Data(frame_index,:)      = Demodulated_Data(frame_index,:);

    else                                          %QAM
        % Soft Demodulation for QAM path
        %-------------------------------
        Demodulated_Data(frame_index,:)           = HF_DemodSoft_QAM(RX_Input_Frames(frame_index,:),Rate,fadingSymbols(frame_index,:),alpha,MSE_Real(frame_index,:), MSE(frame_index,:));
        % Descrampling for QAM path
        %--------------------------
        Descrambled_Data(frame_index,:)           = HF_Descrambling_QAM(Demodulated_Data(frame_index,:),Rate);
        DemodDescrambled_Data(frame_index,:)      = Descrambled_Data(frame_index,:);
    end

end
%*----------------------------------------- BLOCK PROCESSING ----------------------------------------%
% we have two function in the receiver working in block mode
% (HF_Deinterleaving) and (HF_Vitdec_Tailbiting_K7_Punct_R43)

OUT_Decoded_HradDecision = (sign(DemodDescrambled_Data));
% OUT_Decoded_HradDecision = reshape(OUT_Decoded_HradDecision_Matrix',1,[]);

Frame_Count = 1;
N_Blocks = N_Frames/Interleaver_L;
for block_index = 1:N_Blocks
    OUT_Bits_Deinterleaved(block_index,:) = HF_Deinterleaving(DemodDescrambled_Data(Frame_Count:Frame_Count+Interleaver_L-1,:),Rate,Interleaver_L);
%     OUT_Bits_Deinterleaved(block_index,:) = HF_Deinterleaving(OUT_Decoded_HradDecision(Frame_Count:Frame_Count+Interleaver_L-1,:),Rate,Interleaver_L);
    OUT_Bits_Decoded(block_index,:) =  HF_Vitdec_Tailbiting_K7_Punct_R43(-OUT_Bits_Deinterleaved(block_index,:),trellis_t);
    Frame_Count = Frame_Count+Interleaver_L;
end
%----------------------------------------------------------------------------------------------------%









